# Copyright 2022 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_binary", "pw_py_test")
load("//pw_unit_test:pw_golden_test.bzl", "pw_golden_test")

package(default_visibility = ["//visibility:public"])

py_library(
    name = "pw_unit_test",
    srcs = [
        "pw_unit_test/__init__.py",
        "pw_unit_test/golden_test.py",
        "pw_unit_test/rpc.py",
        "pw_unit_test/serial_test_runner.py",
        "pw_unit_test/test_runner.py",
    ],
    imports = ["."],
    deps = [
        "//pw_cli/py:pw_cli",
        "//pw_rpc/py:pw_rpc",
        "//pw_unit_test:unit_test_py_pb2",
        "@pigweed_python_packages//requests",
    ],
)

pw_py_binary(
    name = "golden_test",
    testonly = True,
    srcs = ["pw_unit_test/golden_test.py"],
)

pw_py_test(
    name = "rpc_service_test",
    srcs = ["rpc_service_test.py"],
    args = [
        "--port=3305",  # From pw_rpc/internal/integration_test_ports.gni
        "--test-server-command",
        "$(rootpath //pw_unit_test:test_rpc_server)",
    ],
    data = ["//pw_unit_test:test_rpc_server"],
    tags = ["do_not_run_test"],  # TODO: b/431912506 - Passes locally, not in CI
    deps = [
        ":pw_unit_test",
        "//pw_hdlc/py:pw_hdlc",
    ],
)

# DOCSTAG[pw_unit_test-run-and-compare-test-bazel]
pw_golden_test(
    name = "run_and_compare_test",
    args = [
        "--extra",
        "args",
    ],
    executable = "//pw_unit_test:run_and_compare_test_executable",
    expected = ":run_and_compare_test.expected",
)
# DOCSTAG[pw_unit_test-run-and-compare-test-bazel]

pw_py_test(
    name = "test_group_metadata_test",
    srcs = ["test_group_metadata_test.py"],
    tags = ["manual"],  # TODO: b/431912506 - Fix this test in Bazel.
    deps = [":pw_unit_test"],
)
